#ifndef _tftlcd_H
#define _tftlcd_H

#include "main.h"

//定义LCD彩屏的驱动类型  可根据自己手上的彩屏背面型号来选择打开哪种驱动
//#define TFTLCD_HX8357D

//#define TFTLCD_HX8352C

//#define TFTLCD_ILI9341

//#define TFTLCD_ILI9327

//#define TFTLCD_ILI9486

//#define TFTLCD_R61509V

#define TFTLCD_R61509VN

//#define TFTLCD_R61509V3

//#define TFTLCD_ST7793

//#define TFTLCD_NT5510

//#define TFTLCD_HX8357DN

//#define TFTLCD_ILI9325

//#define TFTLCD_ILI9481

#define TFTLCD_DIR 0 // 0：竖屏  1：横屏  默认竖屏

// TFTLCD地址结构体
typedef struct
{
    uint16_t LCD_CMD;
    uint16_t LCD_DATA;
} TFTLCD_TypeDef;

//使用NOR/SRAM的 Bank1.sector4,地址位HADDR[27,26]=11 A10作为数据命令区分线
//注意设置16位总线时STM32内部会右移一位对齐!
#define TFTLCD_BASE ((uint32_t)(0x6C000000 | 0x000007FE))
#define TFTLCD ((TFTLCD_TypeDef *)TFTLCD_BASE)

// TFTLCD重要参数集
typedef struct
{
    uint16_t width;  // LCD 宽度
    uint16_t height; // LCD 高度
    uint16_t id;     // LCD ID
    uint8_t dir;     // LCD 方向
} _tftlcd_data;

// LCD参数
extern _tftlcd_data tftlcd_data; //管理LCD重要参数
// LCD的前端颜色和背景色
extern uint16_t FRONT_COLOR; //前端颜色 默认红色
extern uint16_t BACK_COLOR;  //背景颜色.默认为白色

//画笔颜色
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430  //灰色

void LCD_WriteCmd(uint16_t cmd);
void LCD_WriteData(uint16_t data);
void LCD_WriteCmdData(uint16_t cmd, uint16_t data);
void LCD_WriteData_Color(uint16_t color);

void TFTLCD_Init(void); //初始化
void LCD_Set_Window(uint16_t sx, uint16_t sy, uint16_t width, uint16_t height);
void LCD_Clear(uint16_t Color); //清屏
void LCD_Fill(uint16_t xState, uint16_t yState, uint16_t xEnd, uint16_t yEnd, uint16_t color);
void LCD_DrawPoint(uint16_t x, uint16_t y); //画点
void LCD_DrawFRONT_COLOR(uint16_t x, uint16_t y, uint16_t color);
uint16_t LCD_ReadPoint(uint16_t x, uint16_t y);
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_DrawLine_Color(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void LCD_DrowSign(uint16_t x, uint16_t y, uint16_t color);
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_Draw_Circle(uint16_t x0, uint16_t y0, uint8_t r);
void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode);
void LCD_ShowNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size);
void LCD_ShowxNum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, uint8_t size, uint8_t mode);
void LCD_ShowString(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t size, uint8_t *p);
void LCD_ShowPicture(uint16_t x, uint16_t y, uint16_t wide, uint16_t high, uint8_t *pic);

#endif
